import Vue from 'vue'
import VueRouter from 'vue-router'
const Login = () => import( /* webpackChunkName:"login_home_welcome" */ '../views/Login.vue')
const Home = () => import( /* webpackChunkName:"login_home_welcome" */ '../views/Home.vue')
const Welcome = () => import( /* webpackChunkName:"login_home_welcome" */ '../components/Welcome.vue')
const Users = () => import( /* webpackChunkName:"user" */ '../components/User/User.vue')
const Rights = () => import( /* webpackChunkName:"power" */ '../components/Role/rights.vue')
const Roles = () => import( /* webpackChunkName:"power" */ '../components/Role/roles.vue')
const Cate = () => import( /* webpackChunkName:"goods" */ '../components/Good/cate.vue')
const Params = () => import( /* webpackChunkName:"goods" */ '../components/Good/params.vue')
const GoodList = () => import( /* webpackChunkName:"goods" */ '../components/Good/goods.vue')
const GoodAdd = () => import( /* webpackChunkName:"goods" */ '../components/Good/addgoods.vue')
const Order = () => import( /* webpackChunkName:"order" */ '../components/Orders/orders.vue')
const Report = () => import( /* webpackChunkName:"report" */ '../components/Reports/reports.vue')
Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'home',
    component: Home,
    redirect: "/welcome",
    children: [
      {
        path: '/welcome',
        name: 'welcome',
        component: Welcome
      },
      {
        path: '/users',
        name: 'users',
        component: Users,
        meta: {
          break: ["商品管理", "商品列表"]
        }
      },
      {
        path: '/goods',
        name: 'goods',
        component: GoodList,
        meta: {
          break: ["商品管理", "商品列表"]
        },
      },
      {
        path: '/goods/addgoods',
        name: 'addgoods',
        component: GoodAdd,
        meta: {
          break: ["商品管理", "添加商品"]
        }
      },
      {
        path: '/roles',
        name: 'role',
        component: Roles,
        meta: {
          break: ["商品管理", "商品列表"]
        }
      },
      {
        path: '/rights',
        name: 'right',
        component: Rights,
        meta: {
          break: ["商品管理", "商品列表"]
        }
      },
      {
        path: '/categories',
        name: 'cate',
        component: Cate,

      },
      {
        path: '/params',
        name: 'params',
        component:Params,
        meta: {
          break: ["商品管理", "商品列表"]
        }
      },
      {
        path: '/reports',
        name: 'reports',
        component: Report,
        meta: {
          break: ["数据统计", "数据报表"]
        }
      },
      {
        path: '/orders',
        name: 'orders',
        component: Order,
        meta: {
          break: ["订单管理", "订单列表"]
        }
      },
    ]
  },
  {
    path: '/',
    name: 'login',
    component: Login
  },
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === "/") {
    return next()
  }
  let token = localStorage.getItem("token")
  if (!token) {
    return next("/")
  }
  next()
})

export default router
